package chapter2.src.com.kkb.array;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

/**
 * @author : wushikai
 * <p>
 * date : 2021-03-15
 */
public class PriorityQueueDemo {


    public static void testOffer() {
        PriorityQueue<String> q = new PriorityQueue<>();  //这个工具类的功能就是实现 VIP 插队, 其他玩家 该干嘛干嘛 的功能;
        // 添加3个元素到队列:
        q.offer("apple");
        q.offer("pear");
        q.offer("banana");
        System.out.println(q.poll()); // apple
        System.out.println(q.poll()); // banana
        System.out.println(q.poll()); // pear
        System.out.println(q.poll()); // null,因为队列为空
    }


    public static void getPersonPQ() {

        PriorityQueue<Person> q = new PriorityQueue<Person>((var1, var2) ->{
            return var1.getAge().compareTo(var2.getAge());}
        );

        q.offer(new Person("林育容", 41));
        q.offer(new Person("罗帅", 40));
        q.offer(new Person("小楼", 30));
        System.out.println(q.poll()); // Boss/V1
        System.out.println(q.poll()); // Bob/A1
        System.out.println(q.poll()); // Alice/A2
        System.out.println(q.poll()); // null,因为队列为空


    }


    public static void main(String[] args) {
        getPersonPQ();
    }


}
